<template>
  <div>
    <van-picker
      title="修改性别"
      show-toolbar
      :columns="columns"
      :default-index="localGender"
      @confirm="onConfrim"
      @cancel="$emit('close')"
      @change="onChange"
    />

  </div>
</template>

<script>
import { updateUserName } from '@/api/user'
export default {
  name: 'UpdateGender',
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  components: {},
  data () {
    return {
      localGender: this.value,
      columns: ['男', '女']
    }
  },
  created () {},
  mounted () {},
  methods: {
    async onConfrim () {
      this.$toast.loading({
        message: '保存中...',
        forbidClick: true,
        duration: 0
      })
      // 发请求
      await updateUserName({
        gender: this.localGender
      })
      // 关闭弹层
      this.$emit('close')
      // 修改父组件name
      this.$emit('input', this.localGender)
      // 提示成功
      this.$toast.success('修改成功')
    },
    onChange (picker, value, index) {
      this.localGender = index
    }
  },
  watch: {},
  computed: {}
}
</script>

<style lang="less" scoped>

</style>
